package fr.umlv.m2.uwp2011.persistence.user.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import fr.umlv.m2.uwp2011.persistence.matiere.dao.HibernateCursusDAO;
import fr.umlv.m2.uwp2011.persistence.user.IUser_CursusDAO;
import fr.umlv.m2.uwp2011.persistence.user.User_Cursus;

public class HibernateUser_CursusDAO implements IUser_CursusDAO {
	private final static HibernateCursusDAO cursusDAO = new HibernateCursusDAO();
	private static final Map<Long, List<User_Cursus>> mapCursusUser = new HashMap<Long, List<User_Cursus>>();
	static {
		//----- cursus with id 1 -------//
		Long cursus_id = 1L;
		List<User_Cursus> list = new ArrayList<User_Cursus>();
		
		User_Cursus userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("etud1");
		list.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("etud2");
		list.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("prof1");
		list.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("prof2");
		list.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("secre1");
		list.add(userCursus);

		mapCursusUser.put(cursus_id, list);
		
		//----- cursus with id 2 -------//
		cursus_id = 2L;
		List<User_Cursus> list2 = new ArrayList<User_Cursus>();
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("etud3");
		list2.add(userCursus);
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("etud4");
		list2.add(userCursus);
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("prof1");
		list2.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("prof3");
		list2.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("secre2");
		list2.add(userCursus);
		
		mapCursusUser.put(cursus_id, list2);
		
		//----- cursus with id 3 -------//
		cursus_id = 3L;
		List<User_Cursus> list3 = new ArrayList<User_Cursus>();
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("etud1");
		list3.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("prof3");
		list3.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("prof1");
		list3.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("prof4");
		list3.add(userCursus);
		
		userCursus = new User_Cursus();
		userCursus.setCursus(cursusDAO.findById(cursus_id));
		userCursus.setUser_id("secre3");
		list2.add(userCursus);
		
		mapCursusUser.put(cursus_id, list3);
		
	}

	@Override
	public List<User_Cursus> findUser_CursusByCursusID(Long cursus_id) {
		return mapCursusUser.get(cursus_id);
	}
}
